﻿namespace Edge.Utilities.Data
{
    using System.Collections.Generic;
    using System.Data;
    using System.Reflection;

    /// <summary>
    /// Contains various data-related utilities.
    /// </summary>
    public static class DataUtilities
    {
        public static DataRow FillDataRow<T>(DataRow dataRow, T item, PropertyInfo[] properties)
        {
            foreach (PropertyInfo property in properties)
            {
                dataRow[property.Name.ToString()] = property.GetValue(item, null);
            }

            return dataRow;
        }

        public static DataTable CreateDataTable<T>(string tableName, IEnumerable<T> collection, PropertyInfo[] properties)
        {
            DataTable dt = new DataTable(tableName);

            foreach (PropertyInfo property in properties)
            {
                dt.Columns.Add(property.Name.ToString());
            }

            return dt;
        }
    }
}
